Creating a Distributable WAR Project With Maven and Jetty

I've always had an itch to give the simplicity of trying out a webapp with jetty:run to people who do not have Maven. It came time to release my project, and people were having trouble getting a third-party component set up (or knowing that they needed to). So naturally I scratched the itch.

My solution was to use with the Maven Assembly Plugin to create a distributable zip file that contains Jetty jars, configuration, the webapp in question and a batch file to execute start.jar.

Basically I created a sub project (webappname-launcher, or similar) which depends on the webapp and Jetty. The assembly component descriptor then defined a target to copy Jetty jars, the src/main/launcher directory, and the war file into.

The src/main/launcher directory contains a run.bat, jetty config, and any distribution files such as README.
Optionally I could include the project generated site with the distribution as well, which could be a nice touch.

As far as the POM is concerned, simply declare the assembly plugin and execute it the the package phase.

This can be accomplished without using a subproject, as part of a regular war. But doing it that way causes jetty jars to be included in your war file. I'm sure there's a way to filter out those dependencies, but I took the most straight forward approach.

I will be using this pattern for all my web projects, but my opinion is that this sort of behavior should be built into the Jetty plugin itself, for example jetty:create-distributable, and operate directly on war projects.

On that note,

I created a launcher for the xmpp4js demo site using this method. It's available for download on SourceForge, here and in SVN here. It requires no Maven, no Jabber server, no Apache proxy. Just download and run :).